Home  |  About  | Last |  Submit  |  Contact
AllQuests.com

Previous Question:  50 Hertz question  CRT TelevisionsNext Question:  For Sale WWE Self Destruction Of Ultimate Warrior  Archive : Completed Business Expired Threads

Question [RESOLVED] Regarding assigning drive letter to partition ( CodeGuru Forums Visual C++ Programming )
Updated: 2008-08-12 06:11:25 (30)
[RESOLVED] Regarding assigning drive letter to partition

Hi all,
Do anyone is having any idea how to use DefineDosDevice in regarding drive letter assignment. My main purpose is to first delete the existing drive letter of a partition then assign my own drive letter without restarting in windows Vista.
Please guide me if anybody have any idea.



Thanks in advance.
Mayank

Answers: [RESOLVED] Regarding assigning drive letter to partition ( CodeGuru Forums Visual C++ Programming )
[RESOLVED] Regarding assigning drive letter to partition

Ya, the reason for doing this that I am working on a project of Disk partitioning, there I need to shrink, extend and move partitions. Everything else is working fine except move.

After moving the partitions windows doesnt recognize the partition until i dont open the disk management utility. I dont have any open files.

I just want to know that is this happening? is there any function here through which windows can recognize my moved partition??

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

It's easy to do.
I wrote a program (of which I posted the exe here) that did just this, using those drive API's. Worked like a charm and Microsoft in Redmond bought a license.
The only thing you need to watch out for is you don't swap the systemdrive.
Unfortunately I am not permitted to share the code with you.
All I can say is you're on the right track with DefineDosDevice and related API's.



[RESOLVED] Regarding assigning drive letter to partition

No-one's saying it's not easy - but the fact that it's easy to do doesn't make it safe to do, nor sensible. The vast majority of Windows programs will have been written with the assumption that a drive letter, once assigned, will remain constant. Therefore, as TheCPUWizard stated earler, it's very difficult to think of a justifiable reason why an app should need to do something like this - especially in view of the havoc that it's likely to cause for everything else.

John E

[RESOLVED] Regarding assigning drive letter to partition

Quote:
Originally Posted by mayank_3103
when I am moving the partitions of the hard drive from one location to the other, to bring the unallocated space in the end of the disk the partition becomes unaccessible. And when I successfully moves that the windows doesnt recognize the moved partition and the partition stops working, but as soon as I open the "diskmgmt.msc" windows assign a new drive letter to that moved partition and it starts working normally.

Is there any solution to my problem??
First of all, I think you need to reassure us that you know what you're doing and that you have a VERY good reason for doing it - because I fear that you're making the (all too common) mistake of assuming that your program is more important than everybody else's.

Suppose that some other programs have files open on those partitions and you unexpectedly start moving them around and changing their drive letters? How are the other programs expected to know what's going on?

Windows is a co-operative multitasking OS (note: 'co-operative' not 'dog-eat-dog'). A big part of being co-operative is that you don't do things that are going to screw up every other running program. In fact, it's doubtful that Windows will let you change the drive letters anyway. The best you can probably hope for is that the letter will get changed at next boot-up.

But even that is inherently unsafe. Suppose that some other programs have saved vital path information in the registry or in a config file. Is your program going to go around helpfully updating all that information or will you just be leaving those other apps to fend for themselves?

John E

[RESOLVED] Regarding assigning drive letter to partition

How to work with GetLogicalDrives() ???

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Please can you tell me why it happens that only when I open the disk management service the window assigns the new drive letter to that partition otherwise it dont even recognize that?

Is there any alternate way to move my partition without losing the drive letter, well I am using "ReadFile"&"WriteFile" SDK functions to relocate my partitions.

Please help with some guidelines.

Thanks.

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

This zip file is having just an exe file. What does this do? I am looking for some coding help through which I can delete the existing drive letter of a partition and assign it a new one.

actually what happening, when I am moving the partitions of the hard drive from one location to the other, to bring the unallocated space in the end of the disk the partition becomes unaccessible. And when I successfully moves that the windows doesnt recognize the moved partition and the partition stops working, but as soon as I open the "diskmgmt.msc" windows assign a new drive letter to that moved partition and it starts working normally.

Is there any solution to my problem??

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Quote:
Originally Posted by mayank_3103
actually what happening, when I am moving the partitions of the hard drive from one location to the other, to bring the unallocated space in the end of the disk the partition becomes unaccessible. And when I successfully moves that the windows doesnt recognize the moved partition and the partition stops working, but as soon as I open the "diskmgmt.msc" windows assign a new drive letter to that moved partition and it starts working normally.

Is there any solution to my problem??


There is ALOT more involved there than assigning the letter.

I am VERY curious as to any use-case where something like this needs to be done on any type of regular basis, such that using the provided GUI (or command line) tools is insufficient....



[RESOLVED] Regarding assigning drive letter to partition

You're barking up the right tree.
I wrote that same program some years ago with attached file as result.
Does it do what you need on Vista?



[RESOLVED] Regarding assigning drive letter to partition

what my problem is suppose I have 2 hard disk connected in my PC
They both having 4 partitions each.
by using the function "GetLogicalDrives" I can get the drive letters of all the partitions. Say suppose C:,D:,E:,F:,G:,H:,I:,J:.
Now the problem is how I am going to identify which drive letters belongs to which Hard drive?
If I just want to have the drive letters of the "PhysicalDrive0" how I am going to differentiate. Is there any function through which I can get the Disk number from drive letters???

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Well I know to get the list of current drive letters by using a function"GetLogicalDrives()"

But it returns the value in the Dword.
In my case the value its returning is 34780

This also I know that to identify the drive letters first convert this digit to binary, then starting from the least significant bit towards its left i start reading the values. least significant bit is drive letter A,next to it is B: and so on. 0 represents non existing and 1 represents existing.

Can anyone can show me how to convery this DWORD value to the assigned drive letters PROGRAMMATICALLY. I am not able to write code for this.

Thanks

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

could you please elaborate your suggestion.
See what happens that whenever I moves a partition, a new GUID as well as a new drive letter is generated at : "HKLM\SYSTEM\MountedDevices" . Now how can I find a new GUID with "QueryDosDevice" and "GetVolumeNameForVolumeMountPoint"?

Should I keep all the guids with me before moving the partition so that to compare after moving the partition?

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Quote:
Originally Posted by fransn
I already told you you are on the right track with DefineDosDevice.
There are 4 other functions that you will need that are part of the same API as DefineDosDevice. Writefile is not one of them.
Fransn - are these 4 functions a secret? Why can't you just tell him what they are?

John E

[RESOLVED] Regarding assigning drive letter to partition

You could use QueryDosDevice and GetVolumeNameForVolumeMountPoint to iterate through your partitions until you find the new one and change that back to the old letter.



[RESOLVED] Regarding assigning drive letter to partition

Well I very well know those 4 functions. But those doesnt solve my problem. coz those 4 functions are in regarding to the drive letters only. And I am looking for somthing that can move my partitions fast as well as efectively.

And the problem is with the drive letters is that I am mentioning here:

Suppose I am having 4 drives in my system naming "C,D,E,F,G"
Now suppose I am moving (E drive to other location and after updating the partition table, windows generate a new drive letter and assign that in place of (E say suppose (L.

Now programmatically How will I identify Which new drive letter is assigned to my recently moved partition? so that I can change back that to the previous Letter. I have the previous drive letter with me, but not the new one!!!

This deleting and assigning the old drive letter can be done with "SetVolumeMountPoint","DeleteVolumeMountPoint". But for this I need to identify the new Drive letter.

Hope you all must have understood my problem!!!!


Thanks

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Hey Guys if you have any confusion regarding my problem then please let me know.
I have nothing to do with the system drive. I am relocating the other partitions. Do you have any idea or technique of moving partitions apart from ReadFile and WriteFile functions.
Or is there any technique of opening this "diskmgmt.msc" service at the background of my application just for 2 sec. But it shld not be visible to the user.

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Thanks fransn,

I understand that you cant share the code but can you please give any idea regarding the API's which I can use. Is there any fast and effective method to move partition to other place at cluster level apart from writeFile() function?

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Quote:
Originally Posted by fransn
Justifiable reasons? network administrators want this kind of functionality.
Ah - that makes some snese.... in my experience, the sworn aim of every network administrator is to cripple everyone's PC to the maximum extent possible..!

John E

[RESOLVED] Regarding assigning drive letter to partition

I already told you you are on the right track with DefineDosDevice.
There are 4 other functions that you will need that are part of the same API as DefineDosDevice. Writefile is not one of them.



[RESOLVED] Regarding assigning drive letter to partition

Justifiable reasons? network administrators want this kind of functionality.



[RESOLVED] Regarding assigning drive letter to partition

Ya, the reason for doing this that I am working on a project of Disk partitioning, there I need to shrink, extend and move partitions. Everything else is working fine except move.

After moving the partitions windows doesnt recognize the partition until i dont open the disk management utility. I dont have any open files.

I just want to know that is this happening? is there any function here through which windows can recognize my moved partition??

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

How to work with GetLogicalDrives() ???

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Quote:
Originally Posted by mayank_3103
when I am moving the partitions of the hard drive from one location to the other, to bring the unallocated space in the end of the disk the partition becomes unaccessible. And when I successfully moves that the windows doesnt recognize the moved partition and the partition stops working, but as soon as I open the "diskmgmt.msc" windows assign a new drive letter to that moved partition and it starts working normally.

Is there any solution to my problem??
First of all, I think you need to reassure us that you know what you're doing and that you have a VERY good reason for doing it - because I fear that you're making the (all too common) mistake of assuming that your program is more important than everybody else's.

Suppose that some other programs have files open on those partitions and you unexpectedly start moving them around and changing their drive letters? How are the other programs expected to know what's going on?

Windows is a co-operative multitasking OS (note: 'co-operative' not 'dog-eat-dog'). A big part of being co-operative is that you don't do things that are going to screw up every other running program. In fact, it's doubtful that Windows will let you change the drive letters anyway. The best you can probably hope for is that the letter will get changed at next boot-up.

But even that is inherently unsafe. Suppose that some other programs have saved vital path information in the registry or in a config file. Is your program going to go around helpfully updating all that information or will you just be leaving those other apps to fend for themselves?

John E

[RESOLVED] Regarding assigning drive letter to partition

It's easy to do.
I wrote a program (of which I posted the exe here) that did just this, using those drive API's. Worked like a charm and Microsoft in Redmond bought a license.
The only thing you need to watch out for is you don't swap the systemdrive.
Unfortunately I am not permitted to share the code with you.
All I can say is you're on the right track with DefineDosDevice and related API's.



[RESOLVED] Regarding assigning drive letter to partition

No-one's saying it's not easy - but the fact that it's easy to do doesn't make it safe to do, nor sensible. The vast majority of Windows programs will have been written with the assumption that a drive letter, once assigned, will remain constant. Therefore, as TheCPUWizard stated earler, it's very difficult to think of a justifiable reason why an app should need to do something like this - especially in view of the havoc that it's likely to cause for everything else.

John E

[RESOLVED] Regarding assigning drive letter to partition

Please can you tell me why it happens that only when I open the disk management service the window assigns the new drive letter to that partition otherwise it dont even recognize that?

Is there any alternate way to move my partition without losing the drive letter, well I am using "ReadFile"&"WriteFile" SDK functions to relocate my partitions.

Please help with some guidelines.

Thanks.

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

This zip file is having just an exe file. What does this do? I am looking for some coding help through which I can delete the existing drive letter of a partition and assign it a new one.

actually what happening, when I am moving the partitions of the hard drive from one location to the other, to bring the unallocated space in the end of the disk the partition becomes unaccessible. And when I successfully moves that the windows doesnt recognize the moved partition and the partition stops working, but as soon as I open the "diskmgmt.msc" windows assign a new drive letter to that moved partition and it starts working normally.

Is there any solution to my problem??

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Hi all,
Do anyone is having any idea how to use DefineDosDevice in regarding drive letter assignment. My main purpose is to first delete the existing drive letter of a partition then assign my own drive letter without restarting in windows Vista.
Please guide me if anybody have any idea.



Thanks in advance.
Mayank

mayank_3103

[RESOLVED] Regarding assigning drive letter to partition

Quote:
Originally Posted by mayank_3103
actually what happening, when I am moving the partitions of the hard drive from one location to the other, to bring the unallocated space in the end of the disk the partition becomes unaccessible. And when I successfully moves that the windows doesnt recognize the moved partition and the partition stops working, but as soon as I open the "diskmgmt.msc" windows assign a new drive letter to that moved partition and it starts working normally.

Is there any solution to my problem??


There is ALOT more involved there than assigning the letter.

I am VERY curious as to any use-case where something like this needs to be done on any type of regular basis, such that using the provided GUI (or command line) tools is insufficient....



[RESOLVED] Regarding assigning drive letter to partition

You're barking up the right tree.
I wrote that same program some years ago with attached file as result.
Does it do what you need on Vista?



Previous Question:  50 Hertz question  AVForums  CRT TelevisionsNext Question:  For Sale WWE Self Destruction Of Ultimate Warrior  AVForums  Archive : Completed Business Expired Threads

- Source: [RESOLVED] Regarding assigning drive letter to partition CodeGuru Forums Visual C++ Programming
- Previous Question: 50 Hertz question AVForums CRT Televisions
- Next Question: For Sale WWE Self Destruction Of Ultimate Warrior AVForums Archive : Completed Business Expired Threads





AllQuests.com


Best dedicated servers   Top dedicated servers   Cheap dedicated servers   Linux dedicated servers   Windows dedicated servers   Unmetered dedicated servers